package com.haoliangtian.ui.order;

import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import android.app.DatePickerDialog;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.icu.util.LocaleData;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.os.Looper;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.format.bg.IBackgroundFormat;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.style.LineStyle;
import com.bin.david.form.data.table.ArrayTableData;
import com.haoliangtian.R;
import com.haoliangtian.bean.OrderNumber;
import com.haoliangtian.utils.ToastUtil;

import java.util.ArrayList;
import java.util.Calendar;

import butterknife.ButterKnife;

/**
 * 订单展示页面<br>
 * 2020/5/22 8:34 PM
 *
 * @author 华软科技
 * @version 1.0
 */
public class OrderFragment extends Fragment {
    private static final String TAG = "✨✨✨✨✨" + OrderFragment.class.getName() + "✨✨✨✨✨";
    private OrderViewModel mViewModel;
    private View view;
    private SmartTable table;//表格
    //条件layout
    private ScrollView condition, addOrder;
    private int pageNo = 1;//页数
    private int pageSize = 100;//每页条数
    private String fhzt = "0";//复核状态
    private String zzzq = "2020年冬小麦";//种植周期
    private String[][] orderData;
    private String tqzq = "2";//统签直签 1统签，2直签
    private String wtxyzz = "0";//委托协议书是否制作 0未制作，1已制作
    private String hgzt;//种植周期ID
    //第一次获取订单信息
    private boolean firstInit = true;
    private boolean firstAdd;

    public static OrderFragment newInstance() {
        OrderFragment fragment = new OrderFragment();
//        Bundle bundle = new Bundle();
//        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.order_fragment, container, false);
        ButterKnife.bind(view);
        table = view.findViewById(R.id.table);
        condition = view.findViewById(R.id.condition);
        addOrder = view.findViewById(R.id.addOrder);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initCondition();
        initViewModel();
        initTable();
        //进来的时候获取一次数据
        selectZZZQ(tv1);
        selectQY(qy1);
    }

    /**
     * 初始化对应的ViewModel
     */
    private void initViewModel() {
        //获取ViewModel
        mViewModel = ViewModelProviders.of(getActivity()).get(OrderViewModel.class);
        //第一次获取订单数据
        mViewModel.getOrderList(pageNo, pageSize, fhzt, zzzq);
        mViewModel.getOrderListOriginal().observe(getViewLifecycleOwner(), new Observer<String[][]>() {
            @Override
            public void onChanged(String[][] orderInfos) {

                orderData = orderInfos;
                updateOrderData();


            }
        });
        //观察订单页面UI状态
        mViewModel.getStatus().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(String s) {
                if (s.equals(OrderViewModel.status_open_condition)) {
                    //打开筛选条件
                    condition.setVisibility(View.VISIBLE);
                } else {
                    //关闭筛选条件
                    condition.setVisibility(View.GONE);
                }
            }
        });
        //观察种植周期对应的各种订单数
        mViewModel.getOrderNumber().observe(getViewLifecycleOwner(), new Observer<OrderNumber.DataBean>() {
            @Override
            public void onChanged(OrderNumber.DataBean dataBean) {
                setData(dataBean);
            }
        });
        //获取发布单位列表
        mViewModel.getFbdwList().observe(getViewLifecycleOwner(), new Observer<ArrayList<String>>() {
            @Override
            public void onChanged(ArrayList<String> list) {
                fbdwAdapter.clear();
                fbdwList = list;
                fbdwAdapter.addAll(list);
            }
        });
        //获取粮食品种列表
        mViewModel.getLspzList().observe(getViewLifecycleOwner(), new Observer<ArrayList<String>>() {
            @Override
            public void onChanged(ArrayList<String> list) {
                lspzAdapter.clear();
                lspzList = list;
                lspzAdapter.addAll(list);
            }
        });
        //获取种植周期列表
        mViewModel.getZzzqList().observe(getViewLifecycleOwner(), new Observer<ArrayList<String>>() {
            @Override
            public void onChanged(ArrayList<String> list) {
                zzzqAdapter.clear();
                zzzqList = list;
                zzzqAdapter.addAll(list);
            }
        });
        //获取种植周期列表
        mViewModel.getZzqyList().observe(getViewLifecycleOwner(), new Observer<ArrayList<String>>() {
            @Override
            public void onChanged(ArrayList<String> list) {
                zzqyAdapter.clear();
                zzqyList = list;
                zzqyAdapter.addAll(list);
            }
        });
        //获取订单添加的结果
        mViewModel.getAddOrderResult().observe(getViewLifecycleOwner(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean result) {
                if (result.booleanValue() && firstAdd) {
                    ToastUtil.showShort(getContext(), "订单添加成功！");

                } else if (!result.booleanValue() && firstAdd) {

                    ToastUtil.showShort(getContext(), "订单添加失败！");
                }
                firstAdd = false;

            }
        });
    }


    private void updateOrderData() {
        Log.e(TAG, "updateOrderData");
        tableData = ArrayTableData.create("粮食订单", mViewModel.getColumnNames(), orderData, null);
        //固定第一列
        tableData.getArrayColumns().get(0).setFixed(true);
        tableData.setOnItemClickListener(new ArrayTableData.OnItemClickListener<String>() {
            @Override
            public void onClick(Column column, String value, String o, int col, int row) {
                String s = tableData.getArrayColumns().get(col).getDatas().get(row);
                Toast.makeText(getContext(), "列:" + col + " 行：" + row + "数据：" + value, Toast.LENGTH_SHORT).show();
            }
        });
        //遍历每一行
        for (int i = 0; i < orderData.length; i++) {

            Column<String> stringColumn = tableData.getArrayColumns().get(tableData.getArrayColumns().size() - 1);
//            stringColumn.setDrawFormat(new IDrawFormat<String>() {
//                @Override
//                public int measureWidth(Column<String> column, int position, TableConfig config) {
//                    return 0;
//                }
//
//                @Override
//                public int measureHeight(Column<String> column, int position, TableConfig config) {
//                    return 0;
//                }
//
//                @Override
//                public void draw(Canvas c, Rect rect, CellInfo<String> cellInfo, TableConfig config) {
//                    Paint paint = config.getPaint();
//                    int color = R.color.github_con_1;
//                    paint.setStyle(Paint.Style.FILL);
//                    paint.setColor(ContextCompat.getColor(getContext(), color));
//                    c.drawRect(rect.left + 5, rect.top + 5, rect.right - 5, rect.bottom - 5, paint);
//                    Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//                    mPaint.setColor(Color.RED);
//                    mPaint.setTextSize(36);
//                    c.drawText(cellInfo.data, (float) (rect.left + 36), rect.top - 26, mPaint);
//                }
//            });

//            String s = tableData.getArrayColumns().get(tableData.getArrayColumns().size() - 1).getDatas().get(i);
        }
        table.setTableData(tableData);
    }

    private TextView tv1, tv2, tv3, tv4, tv5, tv6, qy1, qy2, qy3, lsddfb1, lsddfb2, lsddfb3,
            lsddxy1, lsddxy2, lsddxy3, sczlwtxy1, sczlwtxy2, sczlwtxy3, sczlwtxy4, lsddhg1, lsddhg2, sqrqTv;
    private LinearLayout lsddfb, lsddxy, sczlwtxy, lsddhg, xyqymc, fbddbh, lspz, sqrq, jsdw;
    private Button cx, tj, qk, qx, qd;
    private EditText lspzEdit, sqrqEdit, jsdwEdit, fbddbhEdit, xyqymcEdit;
    private View selectView1;

    /**
     * 初始化筛选条件
     */
    private void initCondition() {
        (tv1 = view.findViewById(R.id.zzzq1)).setOnClickListener(v -> selectZZZQ(v));
        (tv2 = view.findViewById(R.id.zzzq2)).setOnClickListener(v -> selectZZZQ(v));
        (tv3 = view.findViewById(R.id.zzzq3)).setOnClickListener(v -> selectZZZQ(v));
        (tv4 = view.findViewById(R.id.zzzq4)).setOnClickListener(v -> selectZZZQ(v));
        (tv5 = view.findViewById(R.id.zzzq5)).setOnClickListener(v -> selectZZZQ(v));
        (tv6 = view.findViewById(R.id.zzzq6)).setOnClickListener(v -> selectZZZQ(v));

        (qy1 = view.findViewById(R.id.qy1)).setOnClickListener(v -> selectQY(v));
        (qy2 = view.findViewById(R.id.qy2)).setOnClickListener(v -> selectQY(v));
        (qy3 = view.findViewById(R.id.qy3)).setOnClickListener(v -> selectQY(v));

        (lsddfb1 = view.findViewById(R.id.lsddfb1)).setOnClickListener(v -> selectLSDD(v));
        (lsddfb2 = view.findViewById(R.id.lsddfb2)).setOnClickListener(v -> selectLSDD(v));
        (lsddfb3 = view.findViewById(R.id.lsddfb3)).setOnClickListener(v -> selectLSDD(v));

        (lsddxy1 = view.findViewById(R.id.lsddxy1)).setOnClickListener(v -> selectLSDD(v));
        (lsddxy2 = view.findViewById(R.id.lsddxy2)).setOnClickListener(v -> selectLSDD(v));
        (lsddxy3 = view.findViewById(R.id.lsddxy3)).setOnClickListener(v -> selectLSDD(v));

        (sczlwtxy1 = view.findViewById(R.id.sczlwtxy1)).setOnClickListener(v -> selectSCZLWTXY(v));
        (sczlwtxy2 = view.findViewById(R.id.sczlwtxy2)).setOnClickListener(v -> selectSCZLWTXY(v));
        (sczlwtxy3 = view.findViewById(R.id.sczlwtxy3)).setOnClickListener(v -> selectSCZLWTXY(v));
        (sczlwtxy4 = view.findViewById(R.id.sczlwtxy4)).setOnClickListener(v -> selectSCZLWTXY(v));

        (lsddhg1 = view.findViewById(R.id.lsddhg1)).setOnClickListener(v -> selectLSDDHG(v));
        (lsddhg2 = view.findViewById(R.id.lsddhg2)).setOnClickListener(v -> selectLSDDHG(v));

        lsddfb = view.findViewById(R.id.lsddfb);
        lsddxy = view.findViewById(R.id.lsddxy);
        sczlwtxy = view.findViewById(R.id.sczlwtxy);
        lsddhg = view.findViewById(R.id.lsddhg);

        xyqymc = view.findViewById(R.id.xyqymc);
        fbddbh = view.findViewById(R.id.fbddbh);
        lspz = view.findViewById(R.id.lspz);
        sqrq = view.findViewById(R.id.sqrq);
        jsdw = view.findViewById(R.id.jsdw);

        lspzEdit = view.findViewById(R.id.lspzEdit);
        sqrqEdit = view.findViewById(R.id.sqrqEdit);
        jsdwEdit = view.findViewById(R.id.jsdwEdit);
        fbddbhEdit = view.findViewById(R.id.fbddbhEdit);
        xyqymcEdit = view.findViewById(R.id.xyqymcEdit);


        //点击查询
        (cx = view.findViewById(R.id.cx)).setOnClickListener(view -> {
            if (selectView1 == lsddfb1 || selectView1 == lsddfb2 || selectView1 == lsddfb3) {
                String lspz = lspzEdit.getText() == null ? null : lspzEdit.getText().toString().trim();
                String tjsj = sqrqEdit.getText() == null ? null : sqrqEdit.getText().toString().trim();
                String jsdwmc = jsdwEdit.getText() == null ? null : jsdwEdit.getText().toString().trim();
                mViewModel.getOrderList5(pageNo, pageSize, zzzq, fhzt, lspz, tjsj, jsdwmc);

            } else if (selectView1 == lsddxy1 || selectView1 == lsddxy2 || selectView1 == lsddxy3) {
                String ddfbbh = fbddbhEdit.getText() == null ? null : fbddbhEdit.getText().toString().trim();
                String xydwmc = xyqymcEdit.getText() == null ? null : xyqymcEdit.getText().toString().trim();
                mViewModel.getOrderList6(pageNo, pageSize, zzzq, fhzt, tqzq, xydwmc, ddfbbh);
            } else if (selectView1 == sczlwtxy1) {
                String ddfbbh = fbddbhEdit.getText() == null ? null : fbddbhEdit.getText().toString().trim();
                String xydwmc = xyqymcEdit.getText() == null ? null : xyqymcEdit.getText().toString().trim();
                mViewModel.getOrderList7(pageNo, pageSize, zzzq, wtxyzz, tqzq, xydwmc, ddfbbh);
            } else if (selectView1 == sczlwtxy1 || selectView1 == sczlwtxy2 || selectView1 == sczlwtxy3 || selectView1 == sczlwtxy4) {
                String ddfbbh = fbddbhEdit.getText() == null ? null : fbddbhEdit.getText().toString().trim();
                String xydwmc = xyqymcEdit.getText() == null ? null : xyqymcEdit.getText().toString().trim();
                mViewModel.getOrderList6(pageNo, pageSize, zzzq, fhzt, tqzq, xydwmc, ddfbbh);
            } else if (selectView1 == lsddhg1 || selectView1 == lsddhg2) {
                String ddfbbh = fbddbhEdit.getText() == null ? null : fbddbhEdit.getText().toString().trim();
                String xydwmc = xyqymcEdit.getText() == null ? null : xyqymcEdit.getText().toString().trim();
                mViewModel.getOrderList8(pageNo, pageSize, zzzq, fhzt, xydwmc, ddfbbh);
            }
            closeKeyBoard();
            mViewModel.switchCondition();
        });

        //点击清空
        (qk = view.findViewById(R.id.qk)).setOnClickListener(view -> {
            lspzEdit.setText("");
            sqrqEdit.setText("");
            jsdwEdit.setText("");
            fbddbhEdit.setText("");
            xyqymcEdit.setText("");
        });
        //关闭筛选菜单
        view.findViewById(R.id.closeBtn).setOnClickListener(view -> {
            mViewModel.switchCondition();
        });
        //点击添加订单
        (tj = view.findViewById(R.id.tj)).setOnClickListener(view -> {
            addOrder.setVisibility(View.VISIBLE);
            initAddOrderView();
            getAddOrderData();
        });
        //点击取消添加订单
        (qx = view.findViewById(R.id.qx)).setOnClickListener(view -> {
            addOrder.setVisibility(View.GONE);
        });
        //点击确定添加订单
        (qd = view.findViewById(R.id.qd)).setOnClickListener(view -> {
            firstAdd = true;
            closeKeyBoard();
            addOrder.setVisibility(View.GONE);
//            mViewModel.switchCondition();
            String selectDDYXQ = ddyxqEdit.getText() == null ? "0" : ddyxqEdit.getText().toString().trim();
            String selectZLDJYQ = zldjyqEdit.getText() == null ? "" : zldjyqEdit.getText().toString().trim();
            String selectDDDS = dddsEdit.getText() == null ? "0" : dddsEdit.getText().toString().trim();
            mViewModel.addOrder(selectFBDW, selectLSPZ, selectZZZQ, selectZZQY, selectSQRQ, selectDDYXQ, selectZLDJYQ, selectDDDS);
        });


        //点击申请日期
        (sqrqTv = view.findViewById(R.id.sqrqTv)).setOnClickListener(view -> {

                    sqrqPicker.show();
                }
        );

    }

    /**
     * 关闭键盘
     */
    private void closeKeyBoard() {
        //关闭软键盘
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
        if (imm.isActive() && getActivity().getCurrentFocus() != null) {
            if (getActivity().getCurrentFocus().getWindowToken() != null) {
                imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }

    private AppCompatSpinner fbdwSpinner, lspzSpinner, zzzqSpinner, zzqySpinner;
    private ArrayAdapter fbdwAdapter, lspzAdapter, zzzqAdapter, zzqyAdapter;
    private ArrayList<String> fbdwList, lspzList, zzzqList, zzqyList;
    private String selectFBDW, selectLSPZ, selectZZZQ, selectZZQY, selectSQRQ;
    private DatePickerDialog sqrqPicker;
    private AppCompatEditText ddyxqEdit, dddsEdit, zldjyqEdit;

    /**
     * 初始化添加订单view
     */
    private void initAddOrderView() {
        fbdwSpinner = view.findViewById(R.id.fbdwSpinner);
        fbdwAdapter = new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item);
        fbdwSpinner.setAdapter(fbdwAdapter);
        //选择发布单位
        fbdwSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Log.e(TAG, "position:" + position);
                if (fbdwList != null && fbdwList.size() > position) {
                    selectFBDW = fbdwList.get(position);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        lspzSpinner = view.findViewById(R.id.lspzSpinner);
        lspzAdapter = new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item);
        lspzSpinner.setAdapter(lspzAdapter);
        //选择发布单位
        lspzSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (lspzList != null && lspzList.size() > position) {
                    selectLSPZ = lspzList.get(position);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        zzzqSpinner = view.findViewById(R.id.zzzqSpinner);
        zzzqAdapter = new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item);
        zzzqSpinner.setAdapter(zzzqAdapter);
        //选择发布单位
        zzzqSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (zzzqList != null && zzzqList.size() > position) {
                    selectZZZQ = zzzqList.get(position);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


        zzqySpinner = view.findViewById(R.id.zzqySpinner);
        zzqyAdapter = new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item);
        zzqySpinner.setAdapter(zzqyAdapter);
        //选择发布单位
        zzqySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (zzqyList != null && zzqyList.size() > position) {
                    selectZZQY = zzqyList.get(position);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        Calendar calendar = Calendar.getInstance();
        sqrqPicker = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                selectSQRQ = year + "-" + (month + 1) + "-" + dayOfMonth;
                sqrqTv.setText(selectSQRQ);
            }
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));

        ddyxqEdit = view.findViewById(R.id.ddyxqEdit);
        dddsEdit = view.findViewById(R.id.dddsEdit);
        zldjyqEdit = view.findViewById(R.id.zldjyqEdit);

    }

    /**
     * 获取添加订单的初始化数据
     */
    private void getAddOrderData() {

        mViewModel.getFBDW();
        mViewModel.getLSPZ();
        mViewModel.getZZZQ();
        mViewModel.getZZQY();
    }

    /**
     * 显示条件输入框
     *
     * @param v
     */
    private void showEdit(LinearLayout v) {
        if (v == lsddfb) {
            xyqymc.setVisibility(View.GONE);
            fbddbh.setVisibility(View.GONE);
            lspz.setVisibility(View.VISIBLE);
            sqrq.setVisibility(View.VISIBLE);
            jsdw.setVisibility(View.VISIBLE);

        } else if (v == lsddxy) {
            lspz.setVisibility(View.GONE);
            sqrq.setVisibility(View.GONE);
            jsdw.setVisibility(View.GONE);
            xyqymc.setVisibility(View.VISIBLE);
            fbddbh.setVisibility(View.VISIBLE);

        } else if (v == sczlwtxy) {
            lspz.setVisibility(View.GONE);
            sqrq.setVisibility(View.GONE);
            jsdw.setVisibility(View.GONE);
            xyqymc.setVisibility(View.VISIBLE);
            fbddbh.setVisibility(View.VISIBLE);
        } else if (v == lsddhg) {
            lspz.setVisibility(View.GONE);
            sqrq.setVisibility(View.GONE);
            jsdw.setVisibility(View.GONE);
            xyqymc.setVisibility(View.VISIBLE);
            fbddbh.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置订单各种分类的数量展示
     *
     * @param dataBean
     */
    private void setData(OrderNumber.DataBean dataBean) {
        lsddfb1.setText(Html.fromHtml("待复核 " + "<b><font color='red'>" + dataBean.getLsddfb_unchecked() + "</font></b>" + " 笔"));
        lsddfb2.setText(Html.fromHtml("已发布 " + "<b><font color='red'>" + dataBean.getLsddfb_checked() + "</font></b>" + " 笔"));
        lsddfb3.setText(Html.fromHtml("未通过 " + "<b><font color='red'>" + dataBean.getLsddfb_notpass() + "</font></b>" + " 笔"));

        lsddxy1.setText(Html.fromHtml("待复核 " + "<b><font color='red'>" + dataBean.getLsddxy_tq_unchecked() + "</font></b>" + " 笔"));
        lsddxy2.setText(Html.fromHtml("已成交 " + "<b><font color='red'>" + dataBean.getLsddxy_tq_checked() + "</font></b>" + " 笔"));
        lsddxy3.setText(Html.fromHtml("未通过 " + "<b><font color='red'>" + dataBean.getLsddxy_tq_notpass() + "</font></b>" + " 笔"));

        sczlwtxy1.setText(Html.fromHtml("制作委托协议书 " + "<b><font color='red'>" + dataBean.getLsddxy_zq_unmake() + "</font></b>" + " 笔"));
        sczlwtxy2.setText(Html.fromHtml("待复核 " + "<b><font color='red'>" + dataBean.getLsddxy_zq_unchecked() + "</font></b>" + " 笔"));
        sczlwtxy3.setText(Html.fromHtml("已成交 " + "<b><font color='red'>" + dataBean.getLsddxy_zq_checked() + "</font></b>" + " 笔"));
        sczlwtxy4.setText(Html.fromHtml("未通过 " + "<b><font color='red'>" + dataBean.getLsddxy_zq_notpass() + "</font></b>" + " 笔"));

        lsddhg1.setText(Html.fromHtml("未完成 " + "<b><font color='red'>" + dataBean.getLsddxy_hg_uncompleted() + "</font></b>" + " 笔"));
        lsddhg2.setText(Html.fromHtml("已完成 " + "<b><font color='red'>" + dataBean.getLsddxy_hg_completed() + "</font></b>" + " 笔"));
    }

    /**
     * 选择粮食订单回购
     *
     * @param v
     */
    private void selectLSDDHG(View v) {
        selectView1 = v;
        lsddhg1.setBackgroundColor(getResources().getColor(R.color.white));
        lsddhg2.setBackgroundColor(getResources().getColor(R.color.white));
        v.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        showEdit(lsddhg);
        if (v == lsddhg1) {
            fhzt = "1";
            hgzt = "1";
            mViewModel.getOrderList3(pageNo, pageSize, zzzq, fhzt, hgzt);
        } else if (v == lsddhg2) {
            fhzt = "1";
            hgzt = "2";
            mViewModel.getOrderList3(pageNo, pageSize, zzzq, fhzt, hgzt);
        }
    }

    /**
     * 选择生产资料委托响应
     *
     * @param v
     */
    private void selectSCZLWTXY(View v) {
        selectView1 = v;
        sczlwtxy1.setBackgroundColor(getResources().getColor(R.color.white));
        sczlwtxy2.setBackgroundColor(getResources().getColor(R.color.white));
        sczlwtxy3.setBackgroundColor(getResources().getColor(R.color.white));
        sczlwtxy4.setBackgroundColor(getResources().getColor(R.color.white));
        v.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        showEdit(sczlwtxy);
        if (v == sczlwtxy1) {
            tqzq = "2";
            wtxyzz = "0";
            mViewModel.getOrderList2(pageNo, pageSize, zzzq, tqzq, wtxyzz);
        } else if (v == sczlwtxy2) {
            fhzt = "0";
            tqzq = "2";
            mViewModel.getOrderList5(pageNo, pageSize, zzzq, fhzt, tqzq);
        } else if (v == sczlwtxy3) {
            fhzt = "1";
            tqzq = "2";
            mViewModel.getOrderList5(pageNo, pageSize, zzzq, fhzt, tqzq);
        } else if (v == sczlwtxy4) {
            fhzt = "2";
            tqzq = "2";
            mViewModel.getOrderList5(pageNo, pageSize, zzzq, fhzt, tqzq);
        }
    }

    /**
     * 选择粮食订单发布
     * 或者
     * 选择粮食订单响应
     *
     * @param v
     */
    private void selectLSDD(View v) {
        selectView1 = v;
        lsddfb1.setBackgroundColor(getResources().getColor(R.color.white));
        lsddfb2.setBackgroundColor(getResources().getColor(R.color.white));
        lsddfb3.setBackgroundColor(getResources().getColor(R.color.white));
        lsddxy1.setBackgroundColor(getResources().getColor(R.color.white));
        lsddxy2.setBackgroundColor(getResources().getColor(R.color.white));
        lsddxy3.setBackgroundColor(getResources().getColor(R.color.white));
        v.setBackgroundColor(getResources().getColor(R.color.colorAccent));

        if (v == lsddfb1) {
            showEdit(lsddfb);
            fhzt = "0";
            mViewModel.getOrderList(pageNo, pageSize, zzzq, fhzt);
        } else if (v == lsddfb2) {
            showEdit(lsddfb);
            fhzt = "1";
            mViewModel.getOrderList(pageNo, pageSize, zzzq, fhzt);
        } else if (v == lsddfb3) {
            showEdit(lsddfb);
            fhzt = "2";
            mViewModel.getOrderList(pageNo, pageSize, zzzq, fhzt);
        } else if (v == lsddxy1) {
            showEdit(lsddxy);
            fhzt = "0";
            tqzq = "1";
            mViewModel.getOrderList4(pageNo, pageSize, zzzq, fhzt, tqzq);
        } else if (v == lsddxy2) {
            showEdit(lsddxy);
            fhzt = "1";
            tqzq = "1";
            mViewModel.getOrderList4(pageNo, pageSize, zzzq, fhzt, tqzq);
        } else if (v == lsddxy3) {
            showEdit(lsddxy);
            fhzt = "2";
            tqzq = "1";
            mViewModel.getOrderList4(pageNo, pageSize, zzzq, fhzt, tqzq);
        }
    }

    /**
     * 选择平台管理方粮食种植统签
     * 或
     * 选择订购方与种植方粮食收购直签
     * 或
     * 选择订购方粮食回购情况
     *
     * @param v
     */
    private void selectQY(View v) {
        qy1.setBackgroundColor(getResources().getColor(R.color.white));
        qy2.setBackgroundColor(getResources().getColor(R.color.white));
        qy3.setBackgroundColor(getResources().getColor(R.color.white));
        v.setBackgroundColor(getResources().getColor(R.color.colorAccent));

        String condition = ((TextView) v).getText().toString();
        if (condition.equals("平台管理方粮食种植统签")) {
            fhzt = "0";
            //显示对应的子菜单
            sczlwtxy.setVisibility(View.GONE);
            lsddhg.setVisibility(View.GONE);
            lsddfb.setVisibility(View.VISIBLE);
            lsddxy.setVisibility(View.VISIBLE);
            //默认选择待复核
            selectLSDD(lsddfb1);
//            mViewModel.getOrderList(pageNo, pageSize, zzzq, fhzt);
        } else if (condition.equals("订购方与种植方粮食收购直签")) {
            wtxyzz = "0";
            tqzq = "2";
            //显示对应的子菜单
            lsddhg.setVisibility(View.GONE);
            lsddfb.setVisibility(View.GONE);
            lsddxy.setVisibility(View.GONE);
            sczlwtxy.setVisibility(View.VISIBLE);
            selectSCZLWTXY(sczlwtxy1);
//            mViewModel.getOrderList2(pageNo, pageSize, zzzq, tqzq, wtxyzz);
        } else if (condition.equals("订购方粮食回购情况")) {
            fhzt = "1";
            hgzt = "1";
            //显示对应的子菜单
            lsddfb.setVisibility(View.GONE);
            lsddxy.setVisibility(View.GONE);
            sczlwtxy.setVisibility(View.GONE);
            lsddhg.setVisibility(View.VISIBLE);
            selectLSDDHG(lsddhg1);
//            mViewModel.getOrderList3(pageNo, pageSize, zzzq, fhzt, hgzt);
        }

    }

    /**
     * 选择种植周期
     *
     * @param v
     */
    public void selectZZZQ(View v) {
        tv1.setBackgroundColor(getResources().getColor(R.color.white));
        tv2.setBackgroundColor(getResources().getColor(R.color.white));
        tv3.setBackgroundColor(getResources().getColor(R.color.white));
        tv4.setBackgroundColor(getResources().getColor(R.color.white));
        tv5.setBackgroundColor(getResources().getColor(R.color.white));
        tv6.setBackgroundColor(getResources().getColor(R.color.white));
        v.setBackgroundColor(getResources().getColor(R.color.colorAccent));

        zzzq = ((TextView) v).getText().toString();
        if (!firstInit) {
            mViewModel.getOrderList(pageNo, pageSize, zzzq, fhzt);
        }
        Log.e(TAG,"种植周期："+zzzq);
        mViewModel.getDingDanBiShu(zzzq);
    }

    private ArrayTableData<String> tableData;

    /**
     * 初始化表格
     */
    private void initTable() {


//        FontStyle fontStyle = new FontStyle(getContext(), 12, ContextCompat.getColor(getContext(), R.color.arc_text));
//        table.getConfig().setColumnTitleStyle(fontStyle);
        table.getConfig().setHorizontalPadding(0);
        table.getConfig().setVerticalPadding(0);
        table.getConfig().setContentGridStyle(new LineStyle());


        //设置单元格边框颜色
        LineStyle.setDefaultLineColor(Color.WHITE);
        LineStyle.setDefaultLineSize(2);
        table.getConfig()
                //设置是否显示顶部序号列
                .setShowXSequence(false)
                //设置是否显示左侧序号列
                .setShowYSequence(false)
                //设置是否显示表格标题
                .setShowTableTitle(false)
                //固定列标题
                .setFixedTitle(true)
                //设置列标题背景
                .setColumnTitleBackground(new IBackgroundFormat() {
                    @Override
                    public void drawBackground(Canvas canvas, Rect rect, Paint paint) {
                        canvas.drawColor(Color.parseColor("#85BB77"));
                    }
                })
                //设置内容背景
                .setContentBackground(new IBackgroundFormat() {
                    @Override
                    public void drawBackground(Canvas canvas, Rect rect, Paint paint) {
                        canvas.drawColor(getResources().getColor(R.color.order_bg));
                    }
                })
                //设置列标题字体样式
                .setColumnTitleStyle(new FontStyle(40, Color.WHITE))
                //设置内容部分字体样式
                .setContentStyle(new FontStyle(36, Color.BLACK))
                //设置内容单元格左右padding
                .setHorizontalPadding(20)
                //设置内容单元格上下padding
                .setVerticalPadding(20)
                //设置列标题上下padding
                .setColumnTitleVerticalPadding(20)
        ;


    }


}
